package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.hqfinance.domain.HqAccountDealDetail;
import com.ruoyi.hqfinance.domain.vo.HqAccountDealDetailVo;
import com.ruoyi.hqfinance.service.HqAccountDealDetailService;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.utils.TableUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/accountDeal")
@Api(tags = "总部财务-结算账户交易明细-1")
public class HqAccountDealDetailController {

    @Autowired
    private HqAccountDealDetailService hqAccountDealDetailService;
    @Autowired
    private TableService tableService;


    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll(PageDate  pageDate) {
        List<HqAccountDealDetail> accountDealDetails = hqAccountDealDetailService.selectAll(pageDate);
        if (accountDealDetails == null || accountDealDetails.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(accountDealDetails));
        }
    }

    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody HqAccountDealDetail hqAccountDealDetail){
        Boolean isAdd = hqAccountDealDetailService.insert(hqAccountDealDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody HqAccountDealDetail hqAccountDealDetail){
        Boolean isUpdate = hqAccountDealDetailService.update(hqAccountDealDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = hqAccountDealDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody HqAccountDealDetailVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getTimeType() == null){
            return R.fail("请传入相关时间数据");
        }
        List<HqAccountDealDetail> list = hqAccountDealDetailService.search(vo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new HqAccountDealDetail());
        return TableUtils.handleListResponse(list, fieldList, "暂无数据");

    }

}
